package com.codelinecounter.counter;

import java.util.LinkedList;
import java.util.List;

import com.codelinecounter.rule.CodeLineParser;
import com.codelinecounter.rule.CodeLineParserCreator;
import com.codelinecounter.rule.CodeLineParserCreator.CodeLineParserClass;

public class ValidCodeLineCounter {
	private List<CodeLineParser> validCodeLineParser = new LinkedList<CodeLineParser>();
	private int validCodeLineCounter = 0;
	private boolean isValidCodeLine = false;
	
	public ValidCodeLineCounter() throws Exception{
		CodeLineParser parser = CodeLineParserCreator.createCodeLineParser(CodeLineParserClass.NORMAL_CODE_LINE);
		this.validCodeLineParser.add(parser);
	}
	
	public void countValidCodeLine(String codeLine){
		for(CodeLineParser parser : this.validCodeLineParser){
			parser.setCodeLine(codeLine);
			if (parser.parseCodeLine()){
				validCodeLineCounter++;
				this.isValidCodeLine = true;
			} else
				this.isValidCodeLine = false;
		}
	}
	
	public int getLineCount(){
		return this.validCodeLineCounter;
	}
	
	public boolean isValidCodeLine(){
		return this.isValidCodeLine;
	}
}
